program tangqiao;

const num=20;

var yuan:array[1..num] of integer;
    wei:array[1..num,1..num] of longint;
    value:array[1..num,1..num] of longint;
    n:integer;

procedure input;
 var i:integer;
 begin
   writeln('input');
   readln(n);
   for i:=1 to n do
     read(yuan[i]);
 end;


function add(x,y:integer):longint;
  var i:integer;
      total:longint;
  begin
    total:=0;
    for i:=x to y do
      total:=total+yuan[i];
    add:=total;
  end;

procedure guo1;
 var i,j:integer;
 begin
   for i:=1 to n-1 do
     for j:=i to n do
        value[i,j]:=add(i,j);
   for i:=1 to n do
     wei[1,i]:=yuan[i];
   for i:=1 to n-1 do
     wei[2,i]:=wei[1,i]+wei[1,i+1];
 end;

procedure guo2;
 var i,j:integer;
 begin
   for i:=3 to n do
     for j:=1 to n-i+1 do
        begin
          if wei[i-1,j]<wei[i-1,j+1] then
               begin
                 wei[i,j]:=add(j,j+i-1)+wei[i-1,j];
               end
                                     else
               begin
                 wei[i,j]:=add(j,j+i-1)+wei[i-1,j+1];
               end;
        end;
 end;

procedure output;
 var i,j:integer;
 begin
   writeln('output');
   writeln('the min is :',wei[n,1]);
 end;

begin
  input;

  guo1;
  guo2;

  output;
end.